package expressions.slogo;

import java.util.List;
import model.Angle;
import model.Turtle;
import parsing.Token;

@Token(regex = "clearscreen|cs")
public class ClearScreen extends TurtleCommand
{

    public ClearScreen()
    {
        super(0);
    }

    @Override
    protected Double combineResults(List<Double> results, ITurtleContext context)
    {
        Turtle t = context.getTurtle();
        double x, y;
        x = t.getX();
        y = t.getY();

        /*
         * Home sweet home... Also, turn the turtle to face north. (This is how
         * other turtle implementations do it.)
         */
        t.move(Turtle.defaultX, Turtle.defaultY);
        t.turn(Angle.NORTH);

        /*
         * Clear the screen.
         */
        context.getController().clearScreen();

        /*
         * Return how many pixels the turtle moved to get back home.
         */
        return Math.sqrt(Math.pow(x - Turtle.defaultX, 2)
                + Math.pow(y - Turtle.defaultY, 2));
    }

}
